package ua.khpi.si.kit49.diploma.db.dto;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * Class represents road priority of roads between the cities
 * 
 * @author netstalk3r
 * 
 */

@Entity
@Table(name = "road_priority")
public class RoadPriority implements Comparable<RoadPriority> {

	@Id
	@GeneratedValue
	@Column(name = "id", unique = true, nullable = false)
	private Integer id;

	@Column(name = "priority", unique = true, length = 45)
	private String priority;

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "roadPriority", cascade = CascadeType.ALL)
	private Set<ConnectionFeature> connectionsFeature = new HashSet<ConnectionFeature>(
			0);

	public RoadPriority() {
		super();
	}

	public RoadPriority(String prioruty,
			Set<ConnectionFeature> connectionsFeature) {
		super();
		this.priority = prioruty;
		this.connectionsFeature = connectionsFeature;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getPriority() {
		return priority;
	}

	public void setPriority(String prioruty) {
		this.priority = prioruty;
	}

	public Set<ConnectionFeature> getConnectionsFeature() {
		return connectionsFeature;
	}

	public void setConnectionsFeature(Set<ConnectionFeature> connectionsFeature) {
		this.connectionsFeature = connectionsFeature;
	}

	@Override
	public String toString() {
		return "road_priority_id - " + id + "; priority - " + priority;
	}

	@Override
	public int hashCode() {
		int hash = 33;
		hash = hash * 17 + ((id == null) ? 0 : id.hashCode());
		hash = hash * 17 + ((priority == null) ? 0 : priority.hashCode());
		return hash;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof RoadPriority))
			return false;
		RoadPriority entry = (RoadPriority) obj;
		return id.equals(entry.getId()) && priority.equals(entry.getPriority());
	}

	@Override
	public int compareTo(RoadPriority compareRoadPriority) {
		return compareRoadPriority.getId() - this.id;
	}

}
